package org.alanlau.ribbon.controller;

import org.alanlau.ribbon.entity.HouseInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author liukun
 * @version 1.0
 * @date 2020/9/12 10:44
 */
@RestController
@RequestMapping("/call")
public class HouseClientController {
    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private DiscoveryClient discoveryClient;

    @GetMapping("/data")
    public HouseInfo getData(String name) {
        return restTemplate.getForObject("http://demo-server/house/data?name=" + name, HouseInfo.class);
    }

    @GetMapping("/getInfo")
    public Object getInfo(String serviceId) {
        return discoveryClient.getInstances(serviceId);
    }
}
